const path = require("path");
// scss 设置全局变量
function addStyleResource(rule) {
  rule
    .use("style-resource")
    .loader("style-resources-loader")
    .options({
      patterns: [path.resolve(__dirname, "./src/assets/styles/variable.scss")],
    });
}

module.exports = {
  // 配置输出路径
  outputDir: process.env.VUE_APP_OUTDIR,
  // 设置生产环境目录初始路径
  publicPath: process.env.NODE_ENV === "production" ? "./" : "/",
  // 选项...
  configureWebpack: {
    optimization: {
      minimize: process.env.NODE_ENV === "production",
    },
    plugins: [],
  },
  // css: {
  //   loaderOptions: {
  //     css: {},
  //     postcss: {
  //       plugins: [
  //         require('postcss-px2rem')({
  //           remUnit: 16
  //         })
  //       ]
  //     }
  //   }
  // },
  chainWebpack: (config) => {
    // 设置10kb以下的图片转化成base64格式
    config.module
      .rule("images")
      .use("url-loader")
      .loader("url-loader")
      .tap((options) =>
        Object.assign(options, {
          limit: 10240,
        })
      );
    const types = ["vue-modules", "vue", "normal-modules", "normal"];
    types.forEach((type) =>
      addStyleResource(config.module.rule("scss").oneOf(type))
    );
  },
  devServer: {
    port: 8899,
    disableHostCheck: true,
    overlay: {
      warnings: true,
      errors: true,
    },
    open: true,
    https: false,
    proxy: {
      '/api': {
        target: 'http://localhost:8888',
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        },
      }
    },
  },
  lintOnSave: false,
};
